<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>io_context::~io_context</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="Asio">
<link rel="up" href="../io_context.html" title="io_context">
<link rel="prev" href="wrap.html" title="io_context::wrap">
<link rel="next" href="../io_context__basic_executor_type.html" title="io_context::basic_executor_type">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="asio.reference.io_context._io_context"></a><a class="link" href="_io_context.html" title="io_context::~io_context">io_context::~io_context</a>
</h4></div></div></div>
<p>
          <a class="indexterm" name="asio.indexterm.io_context._io_context"></a> 
Destructor.
        </p>
<pre class="programlisting"><span class="special">~</span><span class="identifier">io_context</span><span class="special">();</span>
</pre>
<p>
          On destruction, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a> performs the following
          sequence of operations:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
              For each service object <code class="computeroutput"><span class="identifier">svc</span></code>
              in the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a>
              set, in reverse order of the beginning of service object lifetime,
              performs <code class="computeroutput"><span class="identifier">svc</span><span class="special">-&gt;</span><span class="identifier">shutdown</span><span class="special">()</span></code>.
            </li>
<li class="listitem">
              Uninvoked handler objects that were scheduled for deferred invocation
              on the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a>,
              or any associated strand, are destroyed.
            </li>
<li class="listitem">
              For each service object <code class="computeroutput"><span class="identifier">svc</span></code>
              in the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a>
              set, in reverse order of the beginning of service object lifetime,
              performs <code class="computeroutput"><span class="keyword">delete</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">io_context</span><span class="special">::</span><span class="identifier">service</span><span class="special">*&gt;(</span><span class="identifier">svc</span><span class="special">)</span></code>.
            </li>
</ul></div>
<h6>
<a name="asio.reference.io_context._io_context.h0"></a>
          <span><a name="asio.reference.io_context._io_context.remarks"></a></span><a class="link" href="_io_context.html#asio.reference.io_context._io_context.remarks">Remarks</a>
        </h6>
<p>
          The destruction sequence described above permits programs to simplify their
          resource management by using <code class="computeroutput"><span class="identifier">shared_ptr</span><span class="special">&lt;&gt;</span></code>. Where an object's lifetime is
          tied to the lifetime of a connection (or some other sequence of asynchronous
          operations), a <code class="computeroutput"><span class="identifier">shared_ptr</span></code>
          to the object would be bound into the handlers for all asynchronous operations
          associated with it. This works as follows:
        </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
              When a single connection ends, all associated asynchronous operations
              complete. The corresponding handler objects are destroyed, and all
              <code class="computeroutput"><span class="identifier">shared_ptr</span></code> references
              to the objects are destroyed.
            </li>
<li class="listitem">
              To shut down the whole program, the <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a> function <code class="computeroutput"><span class="identifier">stop</span><span class="special">()</span></code>
              is called to terminate any <code class="computeroutput"><span class="identifier">run</span><span class="special">()</span></code> calls as soon as possible. The <a class="link" href="../io_context.html" title="io_context"><code class="computeroutput"><span class="identifier">io_context</span></code></a>
              destructor defined above destroys all handlers, causing all <code class="computeroutput"><span class="identifier">shared_ptr</span></code> references to all connection
              objects to be destroyed.
            </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2003-2022 Christopher M. Kohlhoff<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_context.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_context__basic_executor_type.html"><img src="../../../next.png" alt="Next"></a>
</div>
</body>
</html>
